<template>
  <div class="lang_page">
    <header-comm></header-comm>

    <div class="bcg">
      <div class="lang_box">
        <div class="header_sele">
          <div class="add_qy">
            <!--  -->
            <a-button type="primary" @click="newadd">新增</a-button>
          </div>
          <div>
            <div class="gl_tjwz" v-if="$store.state.tjwz">
              <langtk class="gl_tjym"></langtk>
            </div>
            <div class="seach">
              <!-- <a-button type="primary" @click="rushcacho">清除缓存</a-button> -->
              <div class="sele">
                <a-input placeholder="请输入key或者中文名称查询 " style="width: 250px" @change="onSearch" />
                <a-icon type="search" class="search" />
              </div>
            </div>
          </div>
        </div>
        <div class="glwz">
          <a-table
            @change="handleChangelist"
            :loading="loading"
            :columns="columns"
            :pagination="pagination"
            :dataSource="data"
          >
            <template slot="operation" slot-scope="text, record, index">
              <div class="editable-row-operations">
                <a class="del" @click="()=>xiugai(record,record.key)">修改</a>
                <!-- <a-popconfirm class="del" title="确定删除吗?" @confirm="() => wzdelete(record,record.key)">
              <a>删除</a>
                </a-popconfirm>-->

                <!-- <a @click="()=>wzone(record,record.key)">置顶</a> -->
              </div>
            </template>
          </a-table>
        </div>
        <!-- 表格-================= -->
      </div>
    </div>
  </div>
</template>

<script>
import headerComm from "../header-comm/header.vue";
import langtk from "./langtk.vue";
const columns = [
  {
    title: "key",
    dataIndex: "keyname"
  },
  {
    title: "中文",
    dataIndex: "cnName",
    scopedSlots: { customRender: "cnName" },
    with: 200
  },
  {
    title: "英文",
    dataIndex: "enName"
  },

  {
    title: "德文",
    dataIndex: "dwName"
  },

  {
    title: "俄文",
    dataIndex: "ruName"
  },
  {
    title: "日文",
    dataIndex: "jaName"
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];

const data = [];
import qs from "qs";
import { setTimeout } from "timers";
export default {
  data() {
    this.cacheData = data.map(item => ({ ...item }));

    return {
      data,
      columns,
      serchvalue: "",
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0,
      current:1

      },
      loading: true,
      dataSource: [],

      langtklist: "",
      addlang: false,
    };
  },
  components: {
    headerComm,
    langtk
  },
  methods: {
    //搜索框
    onSearch(e) {
      this.serchvalue = e.target.value;
      this.handleChangelist(this.pagination);
    },

    //获取语言列表
    handleChangelist(pagination) {
      this.pagination.current=pagination.current
      this.axios
        .post(
          "set/lgList.php",
          qs.stringify({
            page: this.pagination.current,
            pageSize: pagination.defaultPageSize,
            sqdwid: this.$store.state.bbl_sqdwid,
            filed: this.serchvalue
          })
        )
        .then(res => {
          if (res.data.code == 303) {
            this.data = res.data.result.data;
            this.pagination.total = Number(res.data.result.total);
            this.loading = false;
            this.cacheData = this.data.map(item => ({
              ...item
            }));
            for (var i = 0; i < res.data.result.data.length; i++) {
              this.data[i].key = res.data.result.data[i].id_num;
            }
          } else {
            this.data = [];
            this.loading = false;
          }
        });
    },

    //删除
    wzdelete(value, key) {
      const dataSource = [...this.data];
      this.data = dataSource.filter(item => item.key !== key);
      this.axios
        .post("set/lgDelete.php", qs.stringify({ id_num: value.id_num }))
        .then(res => {
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },

    // rushcacho() {
    //   let language = JSON.parse(sessionStorage.getItem("language"));

    //   this.axios
    //     .get(
    //       "http://" +
    //         language.domainName +
    //         "/resetCache/deleteCache?updata=5655840!"
    //     )
    //     .then(res => {
    //       if (res.data.code == 303) {
    //         this.$notification["success"]({
    //           message: "成功",
    //           description: res.data.msg
    //         });
    //       } else {
    //         this.$notification["error"]({
    //           message: "失败",
    //           description: res.data.msg
    //         });
    //       }
    //     });
    // },

    newadd() {
      this.$store.state.tjwz = true;
      this.addlang = true;
    },
    //打开添加面板
    tjwz() {
      this.$store.state.tjwz = true;
    },

    //文字修改
    xiugai(value, key) {
      console.log(value);
      this.langtklist = value;
      this.$store.state.tjwz = true;
    }
  },

  created() {
    let language = JSON.parse(sessionStorage.getItem("language"));
    if (language.cnName == 0) {
      columns[1] = {};
    }
    if (language.enName == 0) {
      columns[2] = {};
    }
    if (language.dwName == 0) {
      columns[3] = {};
    }
    if (language.ruName == 0) {
      columns[4] = {};
    }
    if (language.jaName == 0) {
      columns[5] = {};
    }

    this.handleChangelist(this.pagination);
  }
};
</script>

<style lang='less'>
.lang_box {
  .gl_tjwz {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999999;
    height: 930px;
    .gl_tjym {
      position: absolute;
      width: 80%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
  .header_sele {
    position: absolute;
    top: 55px;
    left: 1% !important;
    z-index: 999;
    text-align: right;
    width: 98% !important;
    background-color: #fff;
    box-shadow: 5px 5px 5px #ccc;
    // height: 50px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0!important;
    .add_qy {
      // width: 50%;
      display: inline-block;
      text-align: left;
      padding: 10px 0;
      height: 50px !important;
      button {
        margin: 0 10px;
      }
      .ant-btn-primary {
        background-color: #1890ff !important;
        border: 0 !important;
      }
    }
    .seach {
      display: inline-block;
      .sele {
        position: relative;
        i {
          position: absolute;
          top: 10px;
          right: 8px;
        }
      }
    }
    .list_head {
      display: inline-block;
      .tit {
        font-size: 16px;
      }
      padding: 10px 15px;
      .fl_right {
        .margin {
          margin: 0 5px;
        }
        .xzl_btn:hover {
          border: 0 !important;
          color: #fff !important;
          background: #1890ff !important;
        }
      }
    }
  }
  .glwz {
    width: 98%;
    position: relative;
    top: 147px;
    left: 1%;
    background-color: #fff;
    border: 1px solid #ccc;

    .ant-table-thead > tr,
    .ant-table-tbody > tr {
      height: 50px !important;
    }
    .ant-table-tbody tr td {
      overflow: hidden; /*超出部分隐藏*/
      white-space: nowrap; /*不换行*/
      text-overflow: ellipsis; /*超出部分文字以...显示*/
      max-width: 200px;
    }
  }
}

.fyloading {
  position: absolute;
  width: 90% !important;
  border: 1px solid #91d5ff;
  background: rgba(255, 255, 255, 0.5);
  padding: 30px;
  height: 800px !important;
  z-index: 999999 !important;
  top: 108px;
  left: 201px;
  .ant-spin-blur {
    opacity: 1 !important;
  }
  .ant-spin-text {
    font-size: 18px !important;
  }
}
.ant-spin-nested-loading > div > .ant-spin {
  top: 100px !important;
}

.del {
  padding-right: 15px;
  color: #40a9ff;
  cursor: pointer;
}
</style>
